//
//  MyCustomCell.m
//  ShoppingList_Demo
//
//  Created by 李金华 on 15/4/20.
//  Copyright (c) 2015年 LJH. All rights reserved.
//

#import "MyCustomCell.h"

#define WIDTH ([UIScreen mainScreen].bounds.size.width)

@implementation MyCustomCell

-(void)awakeFromNib
{

    
        //减按钮

    [_deleteBtn addTarget:self action:@selector(deleteBtnAction:) forControlEvents:UIControlEventTouchUpInside];
//    _deleteBtn.tag = 11;

    
        //购买商品的数量


    
    [_addBtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];
//    _addBtn.tag = 12;


}
//-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
//{
//    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
//    {
//        //布局界面
//        UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(5, 5, WIDTH-10, 95)];
//        bgView.backgroundColor = [UIColor whiteColor];
//        
//        //添加商品图片
//        _goodsImgV = [[UIImageView alloc]initWithFrame:CGRectMake(5, 10, 80, 80)];
//        _goodsImgV.backgroundColor = [UIColor greenColor];
//        [bgView addSubview:_goodsImgV];
//        
//        //添加商品标题
//        _goodsTitleLab = [[UILabel alloc]initWithFrame:CGRectMake(90, 5, 200, 30)];
//        _goodsTitleLab.text = @"afadsfa fa";
//        _goodsTitleLab.backgroundColor = [UIColor clearColor];
//        [bgView addSubview:_goodsTitleLab];
//        
//        //促销价
//        _priceTitleLab = [[UILabel alloc]initWithFrame:CGRectMake(90, 35, 70, 30)];
//        _priceTitleLab.text = @"促销价:";
//        _priceTitleLab.backgroundColor = [UIColor clearColor];
//        [bgView addSubview:_priceTitleLab];
//        
//        //商品价格
//        _priceLab = [[UILabel alloc]initWithFrame:CGRectMake(160, 35, 100, 30)];
//        _priceLab.text = @"1990";
//        _priceLab.textColor = [UIColor redColor];
//        [bgView addSubview:_priceLab];
//        
//        //购买数量
//        _goodsNumLab = [[UILabel alloc]initWithFrame:CGRectMake(90, 65, 90, 30)];
//        _goodsNumLab.text = @"购买数量：";
//        [bgView addSubview:_goodsNumLab];
//        
//        //减按钮
//        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        _deleteBtn.frame = CGRectMake(180, 65, 30, 30);
//        [_deleteBtn setImage:[UIImage imageNamed:@"按钮-.png"] forState:UIControlStateNormal];
//        [_deleteBtn addTarget:self action:@selector(deleteBtnAction:) forControlEvents:UIControlEventTouchUpInside];
//        _deleteBtn.tag = 11;
//        [bgView addSubview:_deleteBtn];
//        
//        //购买商品的数量
//        _numCountLab = [[UILabel alloc]initWithFrame:CGRectMake(210, 65, 50, 30)];
//        _numCountLab.textAlignment = NSTextAlignmentCenter;
//        [bgView addSubview:_numCountLab];
//        
//        //加按钮
//        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        _addBtn.frame = CGRectMake(260, 65, 30, 30);
//        [_addBtn setImage:[UIImage imageNamed:@"按钮+.png"] forState:UIControlStateNormal];
//        [_addBtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];
//        _addBtn.tag = 12;
//        [bgView addSubview:_addBtn];
//        
//        //是否选中图片
//        _isSelectImg = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH - 50, 10, 30, 30)];
//        [bgView addSubview:_isSelectImg];
//        
//        [self addSubview:bgView];
//    }
//    return self;
//}

/**
 *  给单元格赋值
 *
 *  @param goodsModel 里面存放各个控件需要的数值
 */
-(void)addTheValue:(PurchaseCarModel *)goodsModel
{
    
    
//    _goodsImgV.image = [UIImage imageNamed:goodsModel.photoUrl];
    
    [_goodsImgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HostImage,goodsModel.photoUrl]] placeholderImage:[UIImage imageNamed:@"SDWebImageDefault"]];
    _priceTitleLab.text = goodsModel.evaluateContent;
    _goodsTitleLab.text = goodsModel.name;
    _priceLab.text = goodsModel.price;
    _numCountLab.text = [NSString stringWithFormat:@"%@",goodsModel.commodityNo];
    
    if (goodsModel.selectState)
    {
        _selectState = YES;
        _isSelectImg.image = [UIImage imageNamed:@"check_choise"];
    }else{
        _selectState = NO;
        _isSelectImg.image = [UIImage imageNamed:@"check_unchoise"];
    }
    
}

/**
 *  点击减按钮实现数量的减少
 *
 *  @param sender 减按钮
 */
-(void)deleteBtnAction:(UIButton *)sender
{
    //判断是否选中，选中才能点击
    if (_selectState == YES)
    {
        //调用代理
        [self.delegate btnClick:self andFlag:(int)sender.tag];
    }

}
/**
 *  点击加按钮实现数量的增加
 *
 *  @param sender 加按钮
 */
-(void)addBtnAction:(UIButton *)sender
{
    //判断是否选中，选中才能点击
    if (_selectState == YES)
    {
        //调用代理
        [self.delegate btnClick:self andFlag:(int)sender.tag];
    }

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
